﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace DawnOfConquest
{
    public abstract class Piece
    {
        protected int actionPoints;
        protected int stamina;
        protected int strength;
        protected int dex;
        protected int intel;
        protected int will;
        protected int health;
        protected int damage;
        protected int range;
        protected int level;
        protected int xCoor;
        protected int yCoor;
        protected String faction;

        protected string name;
        protected long xp;
        protected Boolean hasMoved;
        protected Boolean hasAttacked;
        protected Tile location;

       // protected List<Ability> abilityList = new List<Ability>();
        public List<Tile> validMoves;

        Texture2D sprite;

        public Texture2D getSprite()
        {
            return sprite;
        }

        public void setValidMoves(List<Tile> list)
        {
            validMoves = list;
        }

        public void getValidMoves()
        {
            return validMoves;
        }

        /*public List<Tile> findValidMoves(Tile[][] map)
        {
            validMoves = new List<Tile>();
            findMoves(location, actionPoints, map);
            return validMoves;
        }

        private void findMoves(Tile location, int ap, Tile[][] map)
        {
            int remainingPoints = ap;
            List<Tile> neighbors = map.getNeighbors(location);

            for (int i = 0; i < neighbors.Count; i++)
            {
                Tile tile = neighbors[i];
                int cost;
                if (tile.getTerrain().Equals("Plain"))
                {
                    cost = 1;
                }
                else if (tile.getTerrain().Equals("Woods"))
                {
                    cost = 2;
                }
                else if (tile.getTerrain().Equals("Mountain"))
                {
                    cost = 4;
                }
                else
                {
                    cost = 999;
                }
                if (remainingPoints >= cost && !validMoves.Contains(neighbors[i]))
                {
                    if (neighbors[i].isEmpty())
                    {
                        validMoves.Add(neighbors[i]);
                        findMoves(neighbors[i], remainingPoints - cost, map);
                        return;
                    }
                    else
                    {
                        if (neighbors[i].getResident().getFaction().Equals(faction))
                        {
                            findMoves(neighbors[i], remainingPoints - cost, map);
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }

        public void movePiece(int xCoor, int yCoor, Tile[][] map)
        {
            if (validMoves.Contains(map[xCoor][yCoor]))
            {
                location.removePiece();
                this.xCoor = xCoor;
                this.yCoor = yCoor;
                map.[xCoor][yCoor].enterPiece(this);
                promptAbility();
                hasMoved = true;
            }
        }*/

        public void move()
        {
            hasMoved = true;
        }

        public Boolean turnOver()
        {
            return hasMoved;
        }

        public void promptAbility()
        {

        }

        public void resetUnit()
        {
            hasMoved = false;
        }

        //public string getClass()
        //{

        //}

        public int getAP()
        {
            return actionPoints;
        }

        public Tile getLocation()
        {
            return location;
        }

        public int getStrength()
        {
            return strength;
        }

        public int getDexterity()
        {
            return dex;
        }

        public int getStamina()
        {
            return stamina;
        }

        public int getIntelligence()
        {
            return intel;
        }

        public int getWillpower()
        {
            return will;
        }

        public int getAttack();

        public int getDefense();

        public int getDamage();

        public int getHealth()
        {
            return health;
        }

        public string getName()
        {
            return name;
        }

        public int getXPosition()
        {
            return xCoor;
        }

        public int getYPosition()
        {
            return yCoor;
        }

        public void applyDamage(int damage)
        {
            health = health - damage;
        }

        public void levelUp();

       /* public List<Ability> getAbilities()
        {
          return abilityList;
        }*/

        public void addStrength(int str)
        {
            strength = strength + str;
        }

        public void addDexterity(int dex)
        {
            this.dex = this.dex + dex;
        }

        public void addStamina(int sta)
        {
            stamina = stamina + sta;
        }

        public void addIntelligence(int intel)
        {
            this.intel = this.intel + intel;
        }

        public void addWillpower(int will)
        {
            this.will = this.will + will;
        }

        public void addActionPoints(int ap)
        {
            actionPoints = actionPoints + ap;
        }

        public void addDamage(int dam)
        {
            damage = damage + dam;
        }

        public String getFaction()
        {
            return faction;
        }

        public void setPosition(int x, int y)
        {
            xCoor = x;
            yCoor = y;
        }
    }
}
